<?php


namespace App\Zesow\Cache\Impl;

use Illuminate\Support\Facades\Cache;
use App\Services\Business\Interfaces\TagCategoryServiceInterface;

class TagCategoryCache
{

    public const KEY_NAME = 'tag_category';

    private $tagCategoryService;

    public function __construct(TagCategoryServiceInterface $tagCategoryService)
    {
        $this->tagCategoryService = $tagCategoryService;
    }

    public function tree(int $shopId)
    {

        if (Cache::has(self::KEY_NAME)) {
            return Cache::get(self::KEY_NAME);
        }
        $tagCategories = $this->tagCategoryService->tree($shopId);
        Cache::put(self::KEY_NAME, $tagCategories);
        return $tagCategories;


    }

    public function destroy(int $shopId): void
    {
        Cache::forget($this->key($shopId));
    }

    private function key(int $shopId): string
    {
        return self::KEY_NAME . '_' . $shopId;
    }

}
